package com.shujia

object Code08Fun {
  def main(args: Array[String]): Unit = {
    val funRes: () => Int = fun(10, 20)

    println(funRes())


    fun2(2,3)

    // 对于函数内部可以再定义一个函数
    def fun2(a:Int,b:Int): Unit = {
      println(s"${a} * ${b}")
    }

    val fun5: () => Int = fun3(3, 4)
    val fun5Res: Int = fun5()
    println(fun5Res)

  }

  /*
    函数作为返回值，将: 和 = 中间使用函数类型进行确定返回值类型
   */
  def fun(a: Int, b: Int): () => Int = {
    println(a * b)
    fun1
  }

  def fun1(): Int = {
    10
  }

  def fun3(a: Int, b: Int): () => Int = {
    println(a * b)

    def fun4(): Int = {
      a * b
    }

    fun4 _
  }
}
